package com.ideaaedi.commonds.lock;

import com.ideaaedi.commonds.function.NoArgConsumer;
import com.ideaaedi.commonds.function.NoArgFunction;

import java.util.function.Consumer;
import java.util.function.Function;

/**
 * 分布式锁支持
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img
 * src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2100.9.8
 */
public interface LockSupport {
    
    /**
     * 执行同步逻辑
     *
     * @param function 业务逻辑块
     * @param param 参数
     *
     * @return 逻辑执行结果
     *
     * @throws NotAcquiredLockException 获取分布式锁时抛出失败
     */
    <P, R> R exec(Function<P, R> function, P param) throws NotAcquiredLockException;
    
    /**
     * 执行同步逻辑
     *
     * @param function 业务逻辑块
     *
     * @return 执行结果
     *
     * @throws NotAcquiredLockException 获取分布式锁时抛出失败
     */
    <R> R exec(NoArgFunction<R> function) throws NotAcquiredLockException;
    
    /**
     * 执行同步逻辑
     *
     * @param consumer 业务逻辑块
     * @param param 参数
     *
     * @throws NotAcquiredLockException 获取分布式锁时抛出失败
     */
    <P> void voidExec(Consumer<P> consumer, P param) throws NotAcquiredLockException;
    
    /**
     * 执行同步逻辑
     *
     * @param consumer 业务逻辑块
     *
     * @throws NotAcquiredLockException 获取分布式锁时抛出失败
     */
    void voidExec(NoArgConsumer consumer) throws NotAcquiredLockException;
    
}
